<template>
  <div>
    <el-alert style="padding: 3px 0px;"
              effect="dark"
              :title="tipsTitle"
              type="warning"
              :closable="false"
              show-icon>
    </el-alert>
    <el-form
      class="input-form"
      label-position="right"
      label-width="120px"
      ref="editForm"
      :rules="propRules"
      :disabled="propReadonly"
      :model="form"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-input-number-number v-model="form.skuQtySafety" :min="0" :max="maxQty" label="安全库存" :controls="false"></el-input-number-number>
          <el-form-item label="日期" prop="busDate">
            <el-date-picker v-model="form.busDate" type="date" format="yyyy/MM/dd" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="得分" prop="score">
            <el-input-number v-model="cpScore"  :precision="1" :min="0" :max="100" :controls="false"/>分
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="库存周转率" prop="rotationRate">
            <el-input-number v-model="form.rotationRate" :precision="1" :min="0" :controls="false" />次/月
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="库存周转率得分" prop="rotationRateScore">
            <el-input-number v-model="form.rotationRateScore" :precision="1" :min="0" :max="100" :controls="false" />分
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">        
        <el-col :span="12">
          <el-form-item label="备货满足率" prop="choiceRate">
            <el-input-number v-model="form.choiceRate" :precision="1" :min="0" :controls="false" />%
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备货满足率得分" prop="choiceRateScore">
            <el-input-number v-model="form.choiceRateScore" :precision="1" :min="0" :max="100" :controls="false" />分
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">  
        <el-col :span="12">
          <el-form-item label="采购响应率" prop="purchaseRate">
            <el-input-number v-model="form.purchaseRate" :precision="1" :min="0" :controls="false" />%
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="采购响应率得分" prop="purchaseRateScore">
            <el-input-number v-model="form.purchaseRateScore" :precision="1" :min="0" :max="100" :controls="false" />分
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="平均周转天数" prop="turnoverDays">
            <el-input-number v-model="form.turnoverDays" :precision="1" :min="0" :controls="false" />天
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="库存周转率占比" prop="rotationPercent">
            <el-input-number v-model="form.rotationPercent" :precision="1" :min="0" :max="100" :controls="false" />%
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">  
        <el-col :span="12">
          <el-form-item label="备货满足率占比" prop="choicePercent">
            <el-input-number v-model="form.choicePercent" :precision="1" :min="0" :max="100" :controls="false" />%
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="采购响应率占比" prop="purchasePercent">
            <el-input-number v-model="form.purchasePercent" :precision="1" :min="0" :max="100" :controls="false" />%
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {},
      viewData: {},
      tipsTitle: '计算公式为： 总得分 = 库存周转率得分*库存周转率占比 + 备货满足率得分*备货满足率占比 + 采购响应率得分*采购响应率占比'
    }
  },
  methods: {},
  created() {
    this.$emit('event-register', {
      validate: callback => {
        if (this.form.rotationPercent + this.form.choicePercent + this.form.purchasePercent != 100) {
          this.utilMessage.warning('库存周转率占比、备货满足率占比、采购响应率占比 加起来之和必须是100')
          return
        }
        this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        this.form.score = this.cpScore
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)

        // 设置switch 元素默认值
      },
      afterSave: () => {},
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: flowButtonKey => {
        return true
      },
      afterFlow: flowButtonKey => {},
      beforeClose: () => {
        return true
      }
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object
  },
  components: {},
  computed: {
    cpScore: {
      get() {
        return this.form.rotationRateScore * this.form.rotationPercent / 100 
          + this.form.choiceRateScore * this.form.choicePercent / 100 
          + this.form.purchaseRateScore * this.form.purchasePercent / 100
      },
      set(value) {
        if (value > 100) {
          value = 100
        }
        this.form.score = value
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
}
</style>
